package com.example.demo.common.utils;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;

public class BaseResponse<T> {
	public static final int RESPONSE_TYPE_NORMAL = 0;
	
	public static final int RESPONSE_TYPE_BUSINESS = 1;
	
	public static final int RESPONSE_TYPE_JSON_ERROR = 2;
	
	public static final int RESPONSE_TYPE_SYSTEN_ERROR = 3;
	/**
	 * 0，默认情况请求正常返回
	 * 1，业务校验不通过返回
	 * 2，传入报文的json格式错误返回
	 * 3，系统捕获到的系统异常返回
	 */
	private int resopnseType = 0;
    private String errorCode;
    private String errorMessage;
    private int status;
    private T data;

    private String extMessage;

    public String getExtMessage() {
        return extMessage;
    }

    public void setExtMessage(String extMessage) {
        this.extMessage = extMessage;
    }

    public BaseResponse() {
    }

    public BaseResponse(T t){
        this.errorCode = "";
        this.errorMessage = "";
        this.status = 0;
        this.data=t;
    }

    public BaseResponse(int status, String errorCode, String errorMessage) {
        this.status = status;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public static BaseResponse success(Object data) {
        return new BaseResponse(data);
    }


    public String getErrorCode() {
        return errorCode;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @JsonProperty("success")
    public boolean isSuccess() {
        return StringUtils.isBlank(errorCode) && StringUtils.isBlank(errorMessage);
    }

	public int getResopnseType() {
		return resopnseType;
	}

	public void setResopnseType(int resopnseType) {
		this.resopnseType = resopnseType;
	}

}
